﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.IO; 
using System.Web;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) 
    {
        dbProcessor my_db = new dbProcessor(); 
        
        HttpResponse response = context.Response;
        HttpRequest request = context.Request;

        
        
        int CompId = Convert.ToInt32(request.Params["CompId"]);

        byte[] selected_image = my_db.select_small_image(CompId);

        if (selected_image == null)
        {
            FileStream fs = File.OpenRead(request.PhysicalApplicationPath + "\\thumbs\\default_small.jpeg");
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, data.Length);

            selected_image = data;
        }
        else
        {
            response.Buffer = true;
            response.BinaryWrite(selected_image);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}